<template>
  <div id="main" style="width: 100%; height: 100%"></div>
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "../../dashboard/mixins/resize";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption ({
        title: {
          text: '来源统计',
          left: 'left'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data: ['热线', '电话', 'Email', '短信'],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis: [
          {
            type: 'value',
            interval: 10,
            max: 40
          }
        ],
        series: [
          {
            name: 'Direct',
            type: 'bar',
            barWidth: '60%',
            data: [{
              value: 32,
              itemStyle: {
                color: '#8470FF'
              }
            },
              {
                value: 24,
                itemStyle: {
                  color: '#4EEE94'
                }
              },
              {
                value: 15,
                itemStyle: {
                  color: '#FFFF00'
                }
              },
              {
                value: 20,
                itemStyle: {
                  color: '#FF6A6A'
                }
              }]
          },
          {
            name:'折线',
            type:'line',
            itemStyle : {  /*设置折线颜色*/
              normal : {
                color: '#FFF5EE'
              }
            },
            data:[32, 24, 15, 20]
          }
        ]
      });
    }
  }
}
</script>

